﻿using System.Collections.Generic;
using System.IO;
using HuaXianQu.ProtoBuffEx.Runtime;
using HuaXianQu.ProtoBuffEx.ToolEditor;
using UnityEditor;
using UnityEngine;

namespace Core.Editor.Proto
{
    public class ServerProtoToDll
    {
        static string winProtocPath => Path.GetFullPath($"{Application.dataPath}/../Temp/protoc.exe");

        static string GenerateProtoCsRootPath
        {
            get { return Path.GetFullPath($"{Application.dataPath}/../Temp/ServerProto"); }
        }
        static string ServerProtocolDllPath
        {
            get { return Path.GetFullPath($"{Application.dataPath}/Plugins/ProtoBuffData/ServerProtocol.dll"); }
        }
        
        static string ProtoDir
        {
            get { return Path.GetFullPath($"{Application.dataPath}/../../Config/ServerProto"); }
        }

        [MenuItem("Assets/Tools/ProtoToDll")]
        [MenuItem("Tools/ProtoToDll")]
        static void ProtoToDll()
        {
            ProtoTool protoTool = new ProtoTool
            {
                GenerateProtoCsRootPath = GenerateProtoCsRootPath,
                ProtoDir = ProtoDir,
                Proto_Paths = new List<string>()
                {
                    ProtoDir,
                    Path.GetFullPath($"{Application.dataPath}/../../Config/GoogleProto"),
                },
            };

            protoTool.GenProtoToCsFile();
            ProtoDllTool protoDllTool = new ProtoDllTool();
            protoDllTool.CompileToDll(
                ServerProtocolDllPath, 
                GenerateProtoCsRootPath,
                new[] { "System", ProtoPathConfig.Inst.GoogleProtobufPath });
        }
    }
}